from PIL import Image
import numpy as np

im = Image.open("gaussian.png")
array=np.array(im)
rows = len(array)
cols = len(array[0])
print(rows,cols)

RED=[200,20,20]
def should_replace(pixel):
    if pixel[0]<=45 and pixel[1]<=45 and pixel[2]<=45:
        return True

def paint_red(row,col):
    if should_replace(array[row,col]) and should_replace(array[row+2,col-2]):
        array[row,col]=RED

def makeup(row,col,distance):
    check_lower_mat = (array[row+distance,col]==RED).all()
    check_upper_mat = (array[row-distance,col]==RED).all()
    check_right_mat = (array[row,col+distance]==RED).all()
    check_left_mat = (array[row,col-distance]==RED).all()
    if (check_lower_mat&check_upper_mat)|(check_left_mat&check_right_mat):
        array[row,col]=RED

def makeup_all(distance):
    for col in range(190,330):
        for row in range(40,150):
            makeup(row,col,distance)

    for col in range(75,190):
        for row in range(40,240):
            makeup(row,col,distance)

for col in range(190,330):
    for row in range(40,150):
        paint_red(row,col)

for col in range(75,190):
    for row in range(40,240):
        paint_red(row,col)

def test():
    for col in range(190,330):
        for row in range(40,150):
            array[row,col]=RED

    for col in range(75,190):
        for row in range(40,240):
            array[row,col]=RED

#makeup_all(10)
#makeup_all(5)
#makeup_all(2)

new_im=Image.fromarray(array)
new_im.show()

